package com.anrongtec.zcpt.util;


import android.content.Context;
import android.util.Log;

import com.anrongtec.zcpt.module.AppModel;
import com.art.base.db.LiteOrmDBUtil;

import java.util.List;

/**
 * 数据库操作工具类
 *
 * @author huiliu
 */
public class DbUtil {
    // 获取服务器本地app与商店是否匹配信息后   更新数据库的信息
    public static void updateLocalInfo(Context context, List<AppModel> apps) {
        List<AppModel> appsFromMaket = Util.getAppsFromMaket(context);
//        Log.e(" 更新数据库的信息0", appsFromMaket.size() + "");
        if (appsFromMaket.size() > 0) {
            for (AppModel app : appsFromMaket) {
                for (AppModel appModel : apps) {
                    if (!app.getAppPackName().equals(appModel.getAppPackName())) {
                        List<AppModel> appPackName = LiteOrmDBUtil.getQueryByWhere(AppModel.class, "appPackName", new String[]{appModel.getAppPackName()});
                        if (appPackName != null) {
                            long insert = LiteOrmDBUtil.insert(appModel);
//                            Log.e(" 更新数据库的信息1", insert + "");
                        }
                    }
                }
            }
        } else {
            for (AppModel appModel : apps) {
                List<AppModel> appPackName = LiteOrmDBUtil.getQueryByWhere(AppModel.class, "appPackName", new String[]{appModel.getAppPackName()});
                if (appPackName != null) {
                    long insert = LiteOrmDBUtil.insert(appModel);
                    Log.e(" 更新数据库的信息1", insert + "");
                }
            }
        }

    }

}
